package com.fusion.core.comm.rpc;

import com.fusion.core.comm.Packet;
import com.fusion.core.interactions.ForwardedInvitationInteraction;
import com.fusion.core.node.Node;

import java.io.IOException;

/**
 * @author SwethaShivakumar 
 * Project: fusion
 * Date: Mar 8, 2009
 * URL: http://fusionwiki.co.cc
 * Mail Me At: shiva@fusionproject.co.cc
 */
public class ForwardedInvitation extends PersistantRPC {

	private static final long serialVersionUID = 1L;
	private String invitationCode;
    private int fromGuid;
    private String fromNickname;

    public ForwardedInvitation() {
    }

    public ForwardedInvitation(Node from, String invitationCode) {
        fromGuid = from.getGuid();
        this.invitationCode = invitationCode;
        this.fromNickname = from.getNickname();
    }

    public void execute(Packet data) throws IOException {
        fromGuid = data.readInt();
        invitationCode = data.readUTF();
        fromNickname = data.readUTF();
        core.queNeedsUserInteraction(new ForwardedInvitationInteraction(con.getRemoteFriend(), fromNickname, fromGuid, invitationCode));
    }

    public Packet serializeTo(Packet p) {
        p.writeInt(fromGuid);
        p.writeUTF(invitationCode);
        p.writeUTF(fromNickname);
        return p;
    }
}
